<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="api.IFacade"%>
<%@ page import="p3_entities.*"%>
<%@ page import="presentation.PhaseBook"%>

<%
	IFacade facadeBean = (IFacade )session.getAttribute("PhaseBookBean");
	
if (facadeBean == null) {
	pageContext.forward("Login.jsp");
}
else {
	Balance loggedProfile = facadeBean.getLoggedProfile();
	Integer loggedUserId = loggedProfile.getUserId();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script src="js/jquery-1.6.2.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>

<link rel="stylesheet"
	href="css/start/jquery-ui-1.8.16.custom.css" type="text/css" />
<link rel="stylesheet" href="css/MainPage.css" type="text/css" />

<script type="text/javascript">

</script>



</head>

<body>
	
	<table>
	<%
		String query = request.getParameter("query");
			if ((query == null) || (query.trim().equals("")))
		query = ".*";
		
			try{
		for (String userName : facadeBean.searchFriends(query)) {
		Balance friendProfile = facadeBean.getProfileByUsername(userName);
		String photoFName = "";
		if (friendProfile.getPhotoid() != null)
			photoFName=friendProfile.getPhotoid().getPhotoPath();
	%>
		<tr>
			<td>
			<hr>
			<a href="MainPage.jsp?userName=<%= userName %>"><%= userName %><br><img id="imgProfilePhoto" alt="No profile photo" src="./image/<%= photoFName %>" style="max-height: 50px;"/></a></td>
		</tr>
	<% 
			} // for each user 
	%>
	<% 
			}
			catch (Exception ex){
			%>
			<script type="text/javascript">
				alert('An error has occured. Please make sure the search expression is a valid regular expression.');
				history.go(-1);
			</script>		
	<%
			}
	%>
	</table>

</body>
</html>


<% } // else do bean != null %>
